

import 'package:elmer_tools/service/ApiEndPoint.dart';
import 'package:elmer_tools/service/ApiHost.dart';
import 'package:json_annotation/json_annotation.dart';

@JsonSerializable()
class ApiConfig {
    List<ApiHost> host;
    Map<String, Map<String, ApiEndPoint>> endpoints;

    ApiConfig({required this.host, required this.endpoints});

    factory ApiConfig.fromJson(Map<String, dynamic> json){

        return ApiConfig(
            host: json["host"] == null ? [] : (json["host"] as List).map((e) => ApiHost.fromJson(e)).toList(),
            endpoints: (json["endPoints"] as Map<String, dynamic>?)!.map((k, v) => MapEntry(k, (v as Map<String, dynamic>).map((k2, v2) => MapEntry(k2, ApiEndPoint.fromJson(v2))))),
        );
    }
    Map<String, dynamic> toJson() {
        return {
            "host": host.map((e) => e.toJson()),
            "endpoints": endpoints.map((k, v) => MapEntry(k, v.map((k2, v2) => MapEntry(k2, v2.toJson())))),
        };
    }
}
